home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / pjc_asm.arc / PJ2.ASM < prev    next >
Assembly Source File  |  1987-12-12  |  8KB  |  254 lines

  1. ; Program to illustrate operation of ALUs and latches in the EGA's
  2. ;  Graphics Data Controller.  Draws a variety of patterns against
  3. ;  a horizontally striped background, using each of the 4 available
  4. ;  logical functions (data unmodified, AND, OR, XOR) in turn to combine
  5. ;  the images with the background.
  6. ; Assembled with MASM 4.0, linked with LINK 3.51.
  7. ; Copyright by Michael Abrash, 11/27/86.
  8. ;
  9. stack    segment    para stack 'STACK'
  10.     db    512 dup(?)
  11. stack    ends
  12. ;
  13. EGA_VIDEO_SEGMENT    equ    0a000h    ;EGA display memory segment
  14. SCREEN_HEIGHT        equ    350
  15. SCREEN_WIDTH_IN_BYTES    equ    80
  16. DEMO_AREA_HEIGHT    equ    336    ;# of scan lines in area
  17.                     ; logical function operation
  18.                     ; is demonstrated in
  19. DEMO_AREA_WIDTH_IN_BYTES equ    40    ;width in bytes of area
  20.                     ; logical function operation
  21.                     ; is demonstrated in
  22. VERTICAL_BOX_WIDTH_IN_BYTES equ    10    ;width in bytes of the box used to
  23.                     ; demonstrate each logical function
  24. ;
  25. ; EGA register equates.
  26. ;
  27. GDC_INDEX    equ    3ceh    ;GDC index register
  28. GDC_ROTATE    equ    3    ;GDC data rotate/logical function
  29.                 ; register index
  30. GDC_MODE    equ    5    ;GDC mode register index
  31. ;
  32. dseg    segment    para common 'DATA'
  33. ;
  34. ; String used to label logical functions.
  35. ;
  36. LabelString    label    byte
  37.     db    'UNMODIFIED    AND       OR        XOR   '
  38. LABEL_STRING_LENGTH    equ    $-LabelString
  39. ;
  40. ; Strings used to label fill patterns.
  41. ;
  42. FillPatternFF    db    'Fill Pattern: 0FFh'
  43. FILL_PATTERN_FF_LENGTH    equ    $ - FillPatternFF
  44. FillPattern00    db    'Fill Pattern: 000h'
  45. FILL_PATTERN_00_LENGTH    equ    $ - FillPattern00
  46. FillPatternVert    db    'Fill Pattern: Vertical Bar'
  47. FILL_PATTERN_VERT_LENGTH    equ    $ - FillPatternVert
  48. FillPatternHorz    db    'Fill Pattern: Horizontal Bar'
  49. FILL_PATTERN_HORZ_LENGTH equ    $ - FillPatternHorz
  50. ;
  51. dseg    ends
  52. ;
  53. ; Macro to set indexed register INDEX of GDC chip to SETTING.
  54. ;
  55. SETGDC    macro    INDEX, SETTING
  56.     mov    dx,GDC_INDEX
  57.     mov    ax,(SETTING SHL 8) OR INDEX
  58.     out    dx,ax
  59.     endm
  60. ;
  61. ;
  62. ; Macro to call BIOS write string function to display text string
  63. ;  TEXT_STRING, of length TEXT_LENGTH, at location ROW,COLUMN.
  64. ;
  65. TEXT_UP    macro    TEXT_STRING, TEXT_LENGTH, ROW, COLUMN
  66.     mov    ah,13h            ;BIOS write string function
  67.     mov    bp,offset TEXT_STRING    ;ES:BP points to string
  68.     mov    cx,TEXT_LENGTH
  69.     mov    dx,(ROW SHL 8) OR COLUMN    ;position
  70.     sub    al,al        ;string is chars only, cursor not moved
  71.     mov    bl,7        ;text attribute is white (light gray)
  72.     int    10h
  73.     endm
  74. ;
  75. cseg    segment    para public 'CODE'
  76.     assume    cs:cseg, ds:dseg
  77. start    proc    near
  78.     mov    ax,dseg
  79.     mov    ds,ax
  80. ;
  81. ; Select 640x350 graphics mode.
  82. ;
  83.     mov    ax,010h
  84.     int    10h
  85. ;
  86. ; ES points to EGA memory.
  87. ;
  88.     mov    ax,EGA_VIDEO_SEGMENT
  89.     mov    es,ax
  90. ;
  91. ; Draw background of horizontal bars.
  92. ;
  93.     mov    dx,SCREEN_HEIGHT/4
  94.                 ;# of bars to draw (each 4 pixels high)
  95.     sub    di,di        ;start at offset 0 in display memory
  96.     mov    ax,0ffffh    ;fill pattern for light areas of bars
  97.     mov    bx,DEMO_AREA_WIDTH_IN_BYTES / 2    ;length of each bar
  98.     mov    si,SCREEN_WIDTH_IN_BYTES - DEMO_AREA_WIDTH_IN_BYTES
  99.     mov    bp,(SCREEN_WIDTH_IN_BYTES * 3) - DEMO_AREA_WIDTH_IN_BYTES
  100. BackgroundLoop:
  101.     mov    cx,bx        ;length of bar
  102.     rep    stosw            ;draw top half of bar
  103.     add    di,si        ;point to start of bottom half of bar
  104.     mov    cx,bx        ;length of bar
  105.     rep    stosw            ;draw bottom half of bar
  106.     add    di,bp        ;point to start of top of next bar
  107.     dec    dx
  108.     jnz    BackgroundLoop
  109. ;
  110. ; Draw vertical boxes filled with a variety of fill patterns
  111. ;  using each of the 4 logical functions in turn.
  112.     SETGDC    GDC_ROTATE, 0        ;select data unmodified
  113.                     ; logical function...
  114.     mov    di,0
  115.     call    DrawVerticalBox        ;...and draw box
  116. ;
  117.     SETGDC    GDC_ROTATE, 08h        ;select AND logical function...
  118.     mov    di,10
  119.     call    DrawVerticalBox        ;...and draw box
  120. ;
  121.     SETGDC    GDC_ROTATE, 10h        ;select OR logical function...
  122.     mov    di,20
  123.     call    DrawVerticalBox        ;...and draw box
  124. ;
  125.     SETGDC    GDC_ROTATE, 18h        ;select XOR logical function...
  126.     mov    di,30
  127.     call    DrawVerticalBox        ;...and draw box
  128. ;
  129. ; Reset the logical function to data unmodified, the default state.
  130. ;
  131.     SETGDC    GDC_ROTATE, 0
  132. ;
  133. ; Label the screen.
  134. ;
  135.     push    ds
  136.     pop    es    ;strings we'll display are passed to BIOS
  137.             ; by pointing ES:BP to them
  138. ;
  139. ; Label the logical functions, using the EGA BIOS's
  140. ;  write string function.
  141. ;
  142.     TEXT_UP    LabelString, LABEL_STRING_LENGTH, 24, 0
  143. ;
  144. ; Label the fill patterns, using the EGA BIOS's
  145. ;  write string function.
  146. ;
  147.     TEXT_UP    FillPatternFF, FILL_PATTERN_FF_LENGTH, 3, 42
  148.     TEXT_UP    FillPattern00, FILL_PATTERN_00_LENGTH, 9, 42
  149.     TEXT_UP    FillPatternVert, FILL_PATTERN_VERT_LENGTH, 15, 42
  150.     TEXT_UP    FillPatternHorz, FILL_PATTERN_HORZ_LENGTH, 21, 42
  151. ;
  152. ; Wait until a key's been hit to reset screen mode & exit.
  153. ;
  154. WaitForKey:
  155.     mov    ah,1
  156.     int    16h
  157.     jz    WaitForKey
  158. ;
  159. ; Finished.  Clear key, reset screen mode and exit.
  160. ;
  161. Done:
  162.     mov    ah,0    ;clear key that we just detected
  163.     int    16h
  164. ;
  165.     mov    ax,3    ;reset to text mode
  166.     int    10h
  167. ;
  168.     mov    ah,4ch    ;exit to DOS
  169.     int    21h
  170. ;
  171. start    endp
  172. ; Subroutine to draw a box 80x336 in size, using currently selected
  173. ;  logical function, with upper left corner at the display memory offset
  174. ;  in DI.  Box is filled with four patterns.  Top quarter of area is
  175. ;  filled with 0FFh (solid) pattern, next quarter is filled with 00h
  176. ;  (empty) pattern, next quarter is filled with 33h (double pixel wide
  177. ;  vertical bar) pattern, and bottom quarter is filled with double pixel
  178. ;  high horizontal bar pattern.
  179. ;
  180. ; Macro to draw a column of the specified width in bytes, one- quarter
  181. ;  of the height of the box, with the specified fill pattern.
  182. ;
  183. DRAW_BOX_QUARTER    macro    FILL, WIDTH
  184.     local    RowLoop, ColumnLoop
  185.     mov    al,FILL            ;fill pattern
  186.     mov    dx,DEMO_AREA_HEIGHT / 4    ;1/4 of the full box height
  187. RowLoop:
  188.     mov    cx,WIDTH
  189. ColumnLoop:
  190.     mov    ah,es:[di]    ;load display memory contents into
  191.                 ; GDC latches (we don't actually care
  192.                 ; about value read into AH)
  193.     stosb            ;write pattern, which is logically
  194.                 ; combined with latch contents for each
  195.                 ; plane and then written to display
  196.                 ; memory
  197.     loop    ColumnLoop
  198.     add    di,SCREEN_WIDTH_IN_BYTES - WIDTH
  199.                 ;point to start of next line down in box
  200.     dec    dx
  201.     jnz    RowLoop
  202.     endm
  203. ;
  204. DrawVerticalBox    proc    near
  205.     DRAW_BOX_QUARTER    0ffh, VERTICAL_BOX_WIDTH_IN_BYTES
  206.                     ;first fill pattern: solid fill
  207.     DRAW_BOX_QUARTER    0, VERTICAL_BOX_WIDTH_IN_BYTES
  208.                     ;second fill pattern: empty fill
  209.     DRAW_BOX_QUARTER    033h, VERTICAL_BOX_WIDTH_IN_BYTES
  210.                     ;third fill pattern: double-pixel
  211.                     ; wide vertical bars
  212.     mov    dx,DEMO_AREA_HEIGHT / 4 / 4
  213.                 ;fourth fill pattern: horizontal bars in
  214.                 ; sets of 4 scan lines
  215.     sub    ax,ax
  216.     mov    si,VERTICAL_BOX_WIDTH_IN_BYTES    ;width of fill area
  217. HorzBarLoop:
  218.     dec    ax        ;0ffh fill (faster to do word than byte DEC)
  219.     mov    cx,si        ;width to fill
  220. HBLoop1:
  221.     mov    bl,es:[di]    ;load latches (don't care about value)
  222.     stosb            ;write solid pattern, through ALUs
  223.     loop    HBLoop1
  224.     add    di,SCREEN_WIDTH_IN_BYTES - VERTICAL_BOX_WIDTH_IN_BYTES
  225.     mov    cx,si        ;width to fill
  226. HBLoop2:
  227.     mov    bl,es:[di]    ;load latches
  228.     stosb            ;write solid pattern, through ALUs
  229.     loop    HBLoop2
  230.     add    di,SCREEN_WIDTH_IN_BYTES - VERTICAL_BOX_WIDTH_IN_BYTES
  231.     inc    ax        ;0 fill (faster to do word than byte DEC)
  232.     mov    cx,si        ;width to fill
  233. HBLoop3:
  234.     mov    bl,es:[di]    ;load latches
  235.     stosb            ;write empty pattern, through ALUs
  236.     loop    HBLoop3
  237.     add    di,SCREEN_WIDTH_IN_BYTES - VERTICAL_BOX_WIDTH_IN_BYTES
  238.     mov    cx,si        ;width to fill
  239. HBLoop4:
  240.     mov    bl,es:[di]    ;load latches
  241.     stosb            ;write empty pattern, through ALUs
  242.     loop    HBLoop4
  243.     add    di,SCREEN_WIDTH_IN_BYTES - VERTICAL_BOX_WIDTH_IN_BYTES
  244.     dec    dx
  245.     jnz    HorzBarLoop
  246. ;    
  247.     ret
  248. DrawVerticalBox    endp
  249. cseg    ends
  250.     end    start
  251.  
  252.